local FixedMonster = class("FixedMonster")
local FightHelper = require("gameLogic.fight.FightHelper")
local GameUtils = require("utils.GameUtils")
local Vector3 = require("utils.Vector3")

function FixedMonster:ctor(monsterId, parent)
    self._monsterId = monsterId
    local resName = FightHelper.getMonsterTeamShowRes(monsterId)
    local object = G_ResourceManager:loadActor(resName)
    local gameObject = GameUtils.instantiate(object, parent.transform)
    local luaBehaviour = gameObject:AddComponent(typeof(CS.LuaBehaviour))
    self._controller = gameObject:AddComponent(typeof(CS.UnityEngine.CharacterController))
    local collider = gameObject:AddComponent(typeof(CS.UnityEngine.SphereCollider))
    collider.isTrigger = true
    collider.radius = 2
    self._controller.center = Vector3.new(0, 1, 0)
    luaBehaviour:SetScriptEnv(self)
end

function FixedMonster:setPosition(pos)
    self.transform.position = pos
end

function FixedMonster:setScale(scale)
    self.transform.localScale = scale
end

function FixedMonster:onTriggerEnter(other)
    if other:CompareTag("Player") then
        if self._talk then
            return
        end
        self._talk = require("view.Npc.MonsterBubble").new(self.gameObject, self._monsterId)
        self._talk.transform.localPosition = Vector3.new(0, 2.5, 0)
        self._talk.transform.localScale = GameUtils.UIWorldScale()
    end
end

function FixedMonster:onTriggerExit(other)
    if other:CompareTag("Player") then
        if self._talk then
            self._talk:close()
            self._talk = nil
        end
    end
end

function FixedMonster:remove()
    GameUtils.destroy(self.gameObject)
end

return FixedMonster
